<%-- 
    Document   : index
    Created on : Apr 24, 2012, 4:09:31 PM
    Author     : acer
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="/connect.jspf"%>
<%@include file="/header.jsp"%>
<%@page import="model.PostModel, model.TagModel, model.UserModel, java.util.Date, util.Utility" %>

<%
    PostModel postModel = new PostModel(con);
    TagModel tagModel = new TagModel(con);
    ResultSet favorite_posts_res = postModel.getPostOrderedLimited("like_count", 3);
    ResultSet most_commented_res = postModel.getPostOrderedLimited("post.comment_count", 3);
    int uid = session.getAttribute("userid") != null ? Integer.parseInt(session.getAttribute("userid").toString()) : -1;    
%>
<!-- Body -->
<div id="bodycontent">
	<div class="contentcontainer">

	<div class="title-text">
	  <h1>Most Favorite Content</h1>
	</div>		

	<div class="contentboxh">		
                <% 
                while(favorite_posts_res.next()) { 
                    ResultSet fav_row = favorite_posts_res;
                %>                  
		  <div class="home-box">
			<div><h3><a href="content.jsp?id=<%= fav_row.getString("post_id") %>"><%= fav_row.getString("title") %></a></h3></div>
			<% if(fav_row.getString("post_type").equals("image")) { %>
			<div>
				<a href="content.jsp?id=<%= fav_row.getString("post_id") %>">
					<img src="<%= "upload" + "/" + fav_row.getString("content") %>" class="thumbnailh" alt="Konten 1"/>
				</a>
			</div>
			<% } else if(fav_row.getString("post_type").equals("link")) {  				
				String[] str = fav_row.getString("content").split("\n");
                                String link = str[0];
				String desc = str[1];
			%>
			<div>
				link : <a href="<%= link %>"><%= link %></a><br />
				description : <%= desc %>
			</div>
			<% } else if(fav_row.getString("post_type").equals("video")) { 
                            String tube_id = fav_row.getString("content").substring(31, fav_row.getString("content").length());                            
			%>
			<div>
				<object type="application/x-shockwave-flash" style="width:560px; height:315px;" data="http://www.youtube.com/v/<%= tube_id %>?version=3">
				<param name="movie" value="http://www.youtube.com/v/<%= tube_id %>?version=3" />
				<param name="allowFullScreen" value="true" />
				<param name="allowscriptaccess" value="always" />
				</object>
			</div>
			<% } %>
			<div class="buttons"><a onclick=doLikeOp("like\@<%= fav_row.getString("post_id")%>","class")><img src=like.png width=20 height=20 alt=like></a><a onclick=doLikeOp("dislike\@<%= fav_row.getString("post_id") %>","class")><img src=dislike.png width=20 height=20 alt=dislike></a></div>
                        <%= postModel.getLikeWithClassString(fav_row.getInt("like_count"), uid, fav_row.getInt("post_id"))%>
			<div><small><i><%= fav_row.getString("comment_count") %> peoples commented this post</i></small></div>
                        <p><small><i>Uploaded by <a href="profile.jsp?id=<%= fav_row.getString("poster_id") %>"><%= fav_row.getString("username") %></a> <%= Utility.getDeltaTimeString(fav_row.getDate("datetime"), new Date()) %> </i></small></p>
			<% 
				
                                ResultSet tag_res = tagModel.getTagInfo(fav_row.getInt("post_id"));
				StringBuilder tag_string = new StringBuilder();
                                while(tag_res.next()) {
                                    tag_string.append(",");
                                }
                                out.println("<p>" + tag_string + "</p>");								
			%>
		  </div>		
		<% } %>
	</div>	

	<!-- Bagian Most Commented -->

	<div class="title-text">
		<h1>Most Commented Content</h1>
	</div>

	<div class="contentboxh">
		<% 
                while(most_commented_res.next()) {
                    ResultSet comm_row = most_commented_res;
                %>		
		  <div class="home-box">
			<div><h3><a href="content.jsp?id=<%= comm_row.getString("post_id") %>"><%= comm_row.getString("title") %></a></h3></div>
			<% if(comm_row.getString("post_type").equals("image")) { %>
			<div>
				<a href="content.jsp?id=<%= comm_row.getString("post_id") %>">
					<img src="<%= "upload" + "/" +  comm_row.getString("content") %>" class="thumbnailh" alt="Konten 1"/>
				</a>
			</div>
			<% } else if(comm_row.getString("post_type").equals("link")) {  
				String[] str = comm_row.getString("content").split("\n");
				String link = str[0];
                                String desc = str[1];
			%>
			<div>
				link : <a href="<%= link %>"><%= link %></a><br />
				description : <%= desc %>
			</div>
			<% } else if(comm_row.getString("post_type").equals("video")) { 				
                                String tube_id = comm_row.getString("content").substring(31, comm_row.getString("content").length());                            
			%>
			<div>
				<object type="application/x-shockwave-flash" style="width:560px; height:315px;" data="http://www.youtube.com/v/<%= tube_id %>?version=3">
				<param name="movie" value="http://www.youtube.com/v/<%= tube_id %>'?version=3" />
				<param name="allowFullScreen" value="true" />
				<param name="allowscriptaccess" value="always" />
				</object>
			</div>
			<% } %>
			<div class="buttons"><a onclick=doLikeOp("like\@<%= comm_row.getString("post_id") %>","class")><img src=like.png width=20 height=20 alt=like></a><a onclick=doLikeOp("dislike\@<%= comm_row.getString("post_id") %>","class")><img src=dislike.png width=20 height=20 alt=dislike></a></div>
                        <%= postModel.getLikeWithClassString(comm_row.getInt("like_count"), uid, comm_row.getInt("post_id")) %>
			<div><small><i><%= comm_row.getString("post_comment_count") %> peoples commented this post</i></small></div>
			<p><small><i>Uploaded by <a href="profile.php?id=<%= comm_row.getString("poster_id") %>"><%= comm_row.getString("username") %></a> <%= Utility.getDeltaTimeString(comm_row.getDate("datetime"), new Date()) %> </i></small></p>
			<% 
				ResultSet tag_res = tagModel.getTagInfo(comm_row.getInt("post_id"));
                                							
				StringBuilder tag_string = new StringBuilder();
                                while(tag_res.next()) {
                                    tag_string.append(",");
                                }
                                out.println("<p>" + tag_string + "</p>");
			%>
		  </div>		
		<% } %>
	</div>			

	</div>
</div>

<%@include file="/footer.jsp"%>
